package com.wgts.wgts.mvp.presenter.imp;

import com.wgts.wgts.mvp.model.IHomePageTimeActionFragmentModel;
import com.wgts.wgts.mvp.presenter.IHomePageContentFragmentPersenter;
import com.wgts.wgts.mvp.presenter.IHomePageTimeActionFragmentPresenter;
import com.wgts.wgts.mvp.view.IHomePageTimeActionFragmentView;
import com.wgts.wgts.netmodle.HttpResultSubscriber;
import com.wgts.wgts.netmodle.req.TimeProductReq;
import com.wgts.wgts.netmodle.resp.ActivityListEntity;
import com.wgts.wgts.netmodle.resp.TimeProductEntity;

public class HomePageTimeActionFragmentPresenter implements IHomePageTimeActionFragmentPresenter {
    private IHomePageTimeActionFragmentView view;

    private IHomePageTimeActionFragmentModel model;

    private int pageSize = 20;

    private int pageIndex = 1;

    private int activityId;

    private String beginTime;

    private String endTime;



    public HomePageTimeActionFragmentPresenter(IHomePageTimeActionFragmentView view, IHomePageTimeActionFragmentModel model) {
        this.view = view;
        this.model = model;
    }


    @Override
    public void timeProduct(int activityId, String beginTime, String endTime) {
        pageIndex = 1;
        TimeProductReq req = new TimeProductReq();
        req.pageSize = String.valueOf(this.pageSize);
        req.pageIndex = String.valueOf(this.pageIndex);
        this.activityId = activityId;
        this.beginTime = beginTime;
        this.endTime = endTime;
        req.activityId = this.activityId;
        req.beginTime = this.beginTime;
        req.endTime = this.endTime;
        model.timeProduct(req, new HttpResultSubscriber<TimeProductEntity>() {
            @Override
            public void onSuccess(TimeProductEntity timeProductEntity) {
                if(timeProductEntity.list.size() < pageSize){
                    view.initTimeProduct(timeProductEntity, true);
                }else{
                    view.initTimeProduct(timeProductEntity, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }

    @Override
    public void moreTimeProdct() {
        TimeProductReq req = new TimeProductReq();
        req.pageSize = String.valueOf(this.pageSize);
        req.pageIndex = String.valueOf(this.pageIndex);
        req.activityId = this.activityId;
        req.beginTime = this.beginTime;
        req.endTime = this.endTime;
        model.timeProduct(req, new HttpResultSubscriber<TimeProductEntity>() {
            @Override
            public void onSuccess(TimeProductEntity timeProductEntity) {
                if(timeProductEntity.list.size() < pageSize){
                    view.moreTimeProduct(timeProductEntity, true);
                }else{
                    view.moreTimeProduct(timeProductEntity, false);
                    pageIndex++;
                }
            }

            @Override
            public void _onError(int status, String msg) {

            }
        });
    }
}
